<!DOCTYPE html>
<html lang="ZH">
<head>
    <meta charset="UTF-8">
    <title>后台首页</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.js"></script>
    <script src="https://cdn.bootcss.com/jquery-cookie/1.4.1/jquery.cookie.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.js"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap-theme.css" rel="stylesheet">
    <script type="text/javascript">
        //编辑
        $(document).ready(function () {
            $("input[name='good_edit']").click(function () {
                var obj = $(this).parent().parent();
                var id = obj.children("td:first-child").text();
                console.log('id:'+id);
                $.ajax({
                    url: '/admin.php/Good/getSingleGood/goodId/'+id,
                    dataType:'json',
                    success: function (res) {
                        if (res.code == 200) {
                            console.log('success');
                            $('#good_panel').empty();
                            $('#good_panel').append(res.data);
                        } else {
                            alert('查询失败');
                        }
                    }
                });
            });
        });

        //添加套餐
        $(document).ready(function () {
            $("#good_add").click(function () {
                console.log('good add');
                $.ajax({
                    url: "/admin.php/Good/preAddGood",
                    dataType: 'json',
                    success: function (res) {
                        if (res.code == 200) {
                            console.log('success');
                            $("#good_panel").empty();
                            $("#good_panel").append(res.data);
                        } else {
                            alert('添加失败，请稍后重试 !');
                        }
                    }
                });
            });
        });

        //删除套餐
        $(document).ready(function () {
            $("input[name='good_delete']").click(function () {
                var obj = $(this).parent().parent();
                var id = obj.children("td:first-child").text();
                console.log('id: '+id);
                var r = confirm('确认删除吗？');
                if (r == true) {
                    $.ajax({
                        url: '/admin.php/good/deleteGood/goodId/'+id,
                        dataType:'json',
                        success: function (res) {
                            if (res.code == 200) {
                                alert("删除成功");
                                obj.hide(500);
                            } else {
                                alert('删除失败');
                            }
                        }
                    });
                }
            });
        });
    </script>
</head>
<body>
<div class="col-md-12" style="background-image: url('__PUBLIC__/img/logo.jpg');height: 120px;margin-bottom: 10px;">
    <div class="col-md-12 text-left">
        <h1><a href="{:U('index/index')}" style="text-decoration: none;color: white;">后台操作界面</a></h1>
    </div>
</div>
<div class="col-md-12 text-right" style="margin-bottom: 10px">
    <h7>当前登录用户&nbsp;&nbsp;<span><b>{$Think.session.user}</b></span>&nbsp;&nbsp;&nbsp;&nbsp;<a href="{:U('index/logout')}">登出</a></h7>
</div>
<div class="col-md-12 row">
    <div class="col-md-2 text-center">
        <ul class="nav nav-pills nav-stacked">
          <li role="presentation" class="active">
				<a type="button" href="{:U('index/index')}" name="menu-btn" id="index" class="btn" style="width: 100%;">首&nbsp;&nbsp;页</a>
			</li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('order/index')}" name="menu-btn" id="order-menu" class="btn" style="width: 100%;">预约处理</a>
            </li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('good/index')}" name="menu-btn" id="good-menu" class="btn" style="width: 100%;">套餐管理</a>
            </li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('user/index')}" name="menu-btn" id="account-menu" class="btn" style="width: 100%;">用户管理</a>
            </li>
            <li role="presentation" class="active">
                <a type="button" href="{:U('HomePage/index')}" name="menu-btn" id="banner-menu" class="btn" style="width: 100%;">首页设置</a>
            </li>
        </ul>
    </div>
    <div class="col-md-10">
        <div class="col-md-12 menu-page" id="good-page" style="border: 1px solid red;padding: 10px;margin-bottom: 10px">
            <h3 style="margin-top: -5px">套餐列表</h3>
            <div id="good_panel" style="overflow-y: auto;overflow-x: auto;width: 100%;height: 500px">
                <table class="table table-condensed table-bordered table-striped table-hover text-center">
                    <tr>
                        <th style="text-align: center">编号</th>
                        <th style="text-align: center">套餐类型</th>
                        <th style="text-align: center">套餐名称</th>
                        <th style="text-align: center">费用</th>
                        <th style="text-align: center">优惠1</th>
                        <th style="text-align: center">优惠2</th>
                        <th style="text-align: center">是否启用</th>
                        <th style="text-align: center">操作</th>
                    </tr>
                    <volist name="list" id="item">
                        <tr>
                            <td>{$item['id']}</td>
                            <td>{$item['class_name']}</td>
                            <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['name']}</td>
                            <td>{$item['price']}</td>
                            <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['nice1']}</td>
                            <td style="white-space: nowrap;overflow: hidden;text-overflow: ellipsis">{$item['nice2']}</td>
                            <td>{$item['status']?'激活':'失效'}</td>
                            <td>
                                <input type="button" name="good_edit" class="btn btn-info" value="编辑">
                                <input type="button" name="good_delete" class="btn btn-danger" value="删除">
                            </td>
                        </tr>
                    </volist>
                </table>
            </div>
        </div>
        <div>
            <input type="button" id="good_add" value="添加套餐">
        </div>
    </div>
</div>
</body>
</html>